<template>
  <div>
    <DoctorHeader titleText="发药"></DoctorHeader>
    <div style="margin: 20px 0;">
      <el-input style="width: 200px; margin-right: 10px;" v-model="query.caseNumber" placeholder="请输入要搜索的挂号单" @keydown="search"></el-input>
    </div>
    <h3>患者信息确认</h3>
    <el-form style="margin: 20px 0" inline label-width="80px">
      <el-form-item label="患者姓名">{{result.register.realName}}</el-form-item>
      <el-form-item label="身份证号">{{result.register.cardNumber}}</el-form-item>
      <el-form-item label="年龄">{{result.register.age}}</el-form-item>
      <el-form-item label="性别">{{result.register.gender}}</el-form-item>
    </el-form>
    <el-table  style="margin-top: 20px;" :data="result.drugList" >
      <el-table-column show-overflow-tooltip label="药品名称" prop="drugInfo.drugName"></el-table-column>
      <el-table-column label="单价" width="120px" prop="drugInfo.drugPrice"></el-table-column>
      <el-table-column label="类型" width="80px" prop="drugInfo.drugType"></el-table-column>
      <el-table-column label="规格" width="120px" prop="drugInfo.drugFormat"></el-table-column>
      <el-table-column label="数量" width="80px" prop="drugNumber"></el-table-column>
      <el-table-column label="开立时间" width="200px" prop="creationTime"></el-table-column>
      <el-table-column>
        <template #default="scope">
          <el-button type="primary" size="small" @click="update(scope.row.id,scope.row.drugId,scope.row.drugNumber)">发药</el-button>
          <el-button type="danger" size="small" @click="backMedical(scope.row.id)">退药</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script setup>
import { reactive } from 'vue';
import DoctorHeader from '@/components/doctor/header'
import { get, post } from '@/util/axios'
const query = reactive({
  caseNumber: ''
})
const result = reactive({
  register: {},
  drugList: []
})
function search(event) {
  if (event.keyCode === 13) {
    getTableData()
  }
}
function getTableData () {
  get('/prescription/fayao', query, content => {//20241115233053933
    result.register = content.register
    result.drugList = content.drugList
  })
}
function update(id,drugId,drugNumber) {
  post('/prescription/update', { id,drugId,drugNumber }, content => {
    getTableData()
  })
}
function backMedical(id){
  post('/prescription/backMedical', { id }, content => {
    getTableData()
  })
}
</script>

<style scoped lang="scss">
</style>
